package sensimulator.intersection;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.image.ImageObserver;

public class Bloodpool implements Drawable {

	private Point2D position;
	
	private Image image;
	
	private double rotation;
	
	private long creationTime;
	
	public Bloodpool(Point2D point) {
		this.position = point;
		image = Toolkit.getDefaultToolkit().createImage("resources/blood.png");
		rotation = Math.random() * Math.PI * 2;
		creationTime = System.currentTimeMillis();
	}
	
	@Override
	public void paint(Graphics g, ImageObserver imageObserver) {
		if (image == null)
			return;
			
		Graphics2D g2 = (Graphics2D) g;
		
		AffineTransform t = new AffineTransform();
		t.translate((int) (position.getX()), (int) (position.getY()));
		t.rotate(rotation);
		
		g2.setTransform(t);	
		g2.drawImage(image, -image.getWidth(imageObserver) / 2, -image.getWidth(imageObserver) / 2, imageObserver);
		
		g2.setTransform(new AffineTransform());
	}

	@Override
	public boolean isDisposed() {
		return (System.currentTimeMillis() - creationTime) > 5000;
	}

	@Override
	public int getZOrder() {
		return Painter.OBJECTS_LAYER;
	}
	
	

}
